package net.sf.google.talk.eclipse.views;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smackx.packet.VCard;

/**
 * Simple class to provide a connection for sending files 
 * @author mgriffa
 */
public class OutgoingFileManager {
	private static final OutgoingFileManager INSTANCE = new OutgoingFileManager();
	private XMPPConnection connection;
	
	private OutgoingFileManager() {
		
	}
	
	public static OutgoingFileManager getInstance() {
		return INSTANCE;
	}

	public void setConnection(XMPPConnection connection) {
		this.connection = connection;
	}

	public void send(String filename, String to) {
        System.out.println("Request to send "+filename+" to "+to);
//        VCard c = new VCard();
        try {
        	Presence p = connection.getRoster().getPresence(to);
        	System.out.println("from: "+p.getFrom());
//			c.load(connection, to);
//			System.out.println("c: "+c);
			
			OutgoinigFileJob job = new OutgoinigFileJob(filename, p.getFrom(), connection);
			
			job.schedule();
			System.out.println("job scheduled");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
